package com.jzo2o.orders.manager.client;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jzo2o.api.customer.AddressBookApi;
import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * 服务保护
 *
 * @Author mr.chen
 * @Date 2025/7/6 11:12
 */
@Component
@Slf4j
public class AddressBookClient {

    @Autowired
    private AddressBookApi addressBookApi;

    @SentinelResource(value = "findAddressBook", fallback = "findAddressBookFallback", blockHandler = "findAddressBookBlock")
    public AddressBookResDTO findById(@PathVariable("id") Long id) {
        return null;
    }

    public AddressBookResDTO findAddressBookFallback(@PathVariable("id") Long id,Throwable throwable) {
        log.error("查询地址失败-触发非熔断限流的降级方法，ID：{}, 异常：", id, throwable);
        return null;
    }

    public AddressBookResDTO findAddressBookBlock(@PathVariable("id") Long id, BlockException e) {
        log.error("查询地址失败-触发熔断限流的降级方法，ID：{}, 异常：", id, e);
        return null;
    }
}
